The onDropContent view modifier allows a view in your script to act as a drop target, accepting files, images, or text dragged in from other apps. This makes it easy to build interactive interfaces that respond to drag-and-drop gestures for your script.
Use onDropContent to:
| Property | Type | Description |
|---|---|---|
types |
UTType[] |
A list of Uniform Type Identifiers (e.g., "public.image", "public.text") that specifies which content types this view can accept. If the dragged content does not match these types, the view does not respond to the drop. |
isTarget |
{ value: boolean; onChanged: (value: boolean) => void } |
A binding object that reflects whether the drag operation is currently hovering over the view. Use this to update UI appearance (e.g., highlight the drop area). |
onResult |
(result) => void |
A callback that provides the dropped content when a valid drop occurs. The result includes text, images, and file URLs if available. |
texts – Plain text strings extracted from the drop.images – Dropped images as UIImage instances.fileURLs – Local file paths of dropped files.In this example:
VStack accepts dropped images ("public.image").